< previous page page_176 next page >

Page 176
LISTING 8.1. CLASS:TestClass.

9f8044bafea36a1f728739c0bb58ef4c.gif
 1: Public Function testReturns(ByVal argInteger As Variant) _
 2: As TestClass
 3:     Dim anotherTestClass As TestClass
 4:     On Error GoTo errtestReturns
 5:
 6:     If argInteger < 32767 Then
 7:         Set anotherTestClass = New TestClass
 8:         anotherTestClass.SomeInteger = argInteger + 100
 9:         Set testReturns = anotherTestClass
10:     End If
11:     Exit Function
12: errtestReturns:
13:     Dim sMethodName As String
14:     sMethodName = testReturns
15:     theErrorHandler.processVBTypeError Err, Me, sMethodName
16:     sMethodName = 
17: End Function
18:
19: Module: modMain
20:
21: Public Sub main()
22:     'theTestClass.tryThis
23:
24:     Dim localClass As Object
25:     'Dim SomeArgument As Integer 'For positive Type-Check Test
26:     Dim SomeArgument As String 'For negative Type-Check Test
27:
28:     SomeArgument = 11 'Positive Type-Check Test
29:     'SomeArgument = string 'Negative Type-Check Test
30:
31:     Set localClass = theTestClass.testReturns(SomeArgument)
32:
33:     If TypeName(localClass) <> Nothing Then
34:         If TypeOf localClass Is TestClass Then
35:             MsgBox localClass.SomeInteger
36:         End If
37:     End If
38: End Sub

Notice Sub main(), starting at line 21. For the sake of convenience, there are two declarations and uses of the same variable, SomeArgument (see line 29). One use is for positive testing (the operation and return you expect) and negative testing (what you don't expect). The modMain module is the surrogate client, whereas TestClass is the server. The type of the return variable, localClass, is the same as the server class, TestClass. Thus, from modMain's viewpoint, there are two objects of the same class, including theTestClass.

 
< previous page page_176 next page >

If you like this book, buy it!